﻿using AnesSystem.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem.ViewModels
{
    class CQTLMaZuiTongJiCtrlViewModel : BaseCountCtrlViewModel<CQTLMaZuiTongJiCtrlViewModel>
    {
        #region Variables
        #endregion

        #region Constructor
        public CQTLMaZuiTongJiCtrlViewModel()
        { }


        #endregion

        #region Properties




        #endregion

        #region 依赖属性

        #endregion

        #region Event

        #endregion

        #region Private Methods
        #endregion

        #region Public/Protected Methods
        public void UpdateDisPatientLinkModelList(BaseCountModel SelBaseCountModel)
        {
            if (SelBaseCountModel == null) return;
            DisPatientLinkModelList.Clear();
            if ("空".Equals(SelBaseCountModel.Name))
                DisPatientLinkModelList = PatientLinkModelList.Where(O =>
                {
                    if (string.IsNullOrEmpty(O.AnesthesiaRecord.Mzff))
                        return true;
                    return false;

                }).ToList();
            else if (SelBaseCountModel.Name != null)
            {
                DisPatientLinkModelList = PatientLinkModelList.Where(O =>
                {
                    if (!string.IsNullOrEmpty(O.AnesthesiaRecord.Mzff))
                        return getMzffTL(O.AnesthesiaRecord.Mzff).Equals(SelBaseCountModel.Name);
                    return false;

                }).ToList();
            }
        }

        public override void UpdateBaseCountModelList()
        {
            foreach (PatientLinkModel patientLinkModel in PatientLinkModelList)
            {

                bool onOff = true;
                //Mzff麻醉方式
                //获取手术医生姓名
                if (patientLinkModel.AnesthesiaRecord.Mzff != null)
                {


                    string mzff = getMzffTL(patientLinkModel.AnesthesiaRecord.Mzff);
                    
                    foreach (BaseCountModel baseCountModel in BaseCountModelList)
                    {
                        if (baseCountModel.Name.Equals(mzff))
                        {
                            onOff = false;
                            baseCountModel.Count++;
                        }
                    }
                    if (onOff && !string.IsNullOrEmpty(mzff))
                    {
                        BaseCountModel baseCountModel = new BaseCountModel();
                        baseCountModel.Name = mzff;
                        baseCountModel.Count = 1;
                        BaseCountModelList.Add(baseCountModel);
                    }
                }
            }
        }

        private string getMzffTL(string mzff)
        {

            if (null == mzff || mzff.Equals(""))
            { //无麻醉
                return "空";
            }
            else
            {
                if (mzff.Contains("气管插管全麻")|| mzff.Contains("复合麻醉(插管全麻"))
                {  //全麻
                    return "全麻";
                }
                else if (mzff.Contains("椎管内麻醉") || mzff.Contains("复合麻醉(椎管内麻醉"))
                {  //椎管内麻醉
                    return "椎管内麻醉";
                }
                else if (mzff.Contains("神经阻滞麻醉") || mzff.Contains("复合麻醉(神经阻滞"))
                {  //神经阻滞
                    return "神经阻滞";
                }
                else
                {  //其它麻醉
                    return "其它麻醉";
                }
            }
        }

        #endregion

        #region EventHandlers

        #endregion
    }
}
